Video from URL
import SwiftUI
import AVKit
struct ContentView: View {
var body: some View {
VStack {
player().frame(height: UIScreen.main.bounds.height / 3)
Spacer()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct player: UIViewControllerRepresentable {
func makeUIViewController(context: UIViewControllerRepresentableContext<player>) ->
AVPlayerViewController {
let url = "https://ivoronline.com/BachataBasic.mp4"
let player1 = AVPlayer(url: URL(string: url)!)
let controller = AVPlayerViewController()
controller.player = player1
return controller
}
public func updateUIViewController(_ uiViewController: AVPlayerViewController, context:
UIViewControllerRepresentableContext<player>) {
}
}
Video from local File
let url = Bundle.main.url(forResource: "Pexels", withExtension: "mp4")
let player1 = AVPlayer(url: url!)